<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>栏目树</title>
    <jsp:include page="../../../../head.jsp"/>
    <style type="text/css">
        .ui-widget-content {
            border: 0
        }
    </style>
</head>
<script type="text/javascript">
    var obj;
    var setting = {
        async: {
            enable: true,
            url: "mod-treedata",
            autoParam: ["id=id"]
        },
        data: {
//            key: {},
            simpleData: {
                pIdKey: "parent.id"
            }
        },
        callback: {
            onClick: function (event, treeId, treeNode, clickFlag) {
                $('#center', window.parent.document).attr("src",
                                                       "mod-pms?id=" + treeNode.id);
            },
            onNodeCreated: function (event, treeId, treeNode) {
                if (treeNode.isParent && treeNode.level < 1) {
                    obj.reAsyncChildNodes(treeNode, "refresh");
                }
            }
        }
    };
    function filter(treeId, parentNode, childNodes) {
        if (!childNodes)
            return null;
        return childNodes.modules;
    }

    function refresh(pid) {
        var node = obj.getNodeByParam("id", pid);
        obj.reAsyncChildNodes(node, "refresh");
    }
    var add = function (parentId) {
        var url = "mod-manage";
        if (parentId) {
            url = "mod-manage?parent.id=" + parentId;
        }
        window.parent.jw.dialog({
                                    iframe: url,
                                    width: 600,
                                    height: 250
                                });
    };
    var addsub = function () {
        var obj = $.fn.zTree.getZTreeObj("modtree").getSelectedNodes()[0];
        if (obj) {
            add(obj.id);
        } else {
            window.parent.jw.alert("请选择需要新增子模块的模块!");
        }
    };
    function update() {
        var treeObj = $.fn.zTree.getZTreeObj("modtree");
        var obj = treeObj.getSelectedNodes()[0];
        if (obj) {
            var url = "mod-manage?id=" + obj.id;
            if (obj.parentTId) {
                url += "&parent.id=" + treeObj.getNodeByTId(obj.parentTId).id;

            }
            window.parent.jw.dialog({
                                        iframe: url,
                                        width: 600,
                                        height: 250
                                    });
        } else {
            window.parent.jw.alert("请选择需要修改的模块!");
        }
    }
    $(document).ready(function () {
        obj = $.fn.zTree.init($("#modtree"), setting);
        $("#treeButton input:button").button().css("font-size", "60%");
    });
</script>
<body class="ui-widget-content" style="height: 100%">
<div style="width: 100%;">
    <div id="treeButton" style="">
        <input id="addmod" type="button" value="新增模块" onclick="add()"/> <input
            id="addsubmod" type="button" value="新增子模块" onclick="addsub()"/> <input
            id="update" type="button" value="修改模块" onclick="update()"/>
    </div>
    <ul id="modtree" class="ztree"></ul>
</div>
</body>
</body>
</html>
